<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 2000px;
        }
    </style>
</head>

<body>

    <script>
        function throttle(fn, delay) {
            let attr = true
            return function () {
                if (!attr) {
                    return false
                }
                attr = false;
                setTimeout(() => {
                    fn();
                    attr = true
                }, delay);
            }
        }

        function showTop() {
            var scrollTop = document.body.scrollTop || document.documentElement.scrollTop;
            console.log('滚动条位置：' + scrollTop);
        }
        window.onscroll = throttle(showTop, 2000)
    </script>
</body>

</html>